package queries;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Class for representing a query 
 * 
 * @author Vika
 * @author ak2765
 */
public final class Query {

	private final double precision;
	
	private final List<String> keywords;

	public Query(String[] keywords, double precision) {
		this(Arrays.asList(keywords.clone()), precision);
	}
	
	public Query(List<String> keywords, double precision) {
		this.keywords = new ArrayList<String>(keywords);
		this.precision = precision;
	}

	public double getPrecision() {
		return precision;
	}

	public List<String> getListOfWords() {
		return keywords;
	}

	/**
	 * @return
	 */
	public String nativeStringQuery() {
		StringBuilder buff = new StringBuilder(this.keywords.get(0));
		for(int i=1;i<this.keywords.size();i++) {
			buff.append(" ").append(this.keywords.get(i));
		}
		return buff.toString();
	}

	/**
	 * Append new keywords to query
	 * 
	 * @param keyWordsToAdd
	 * @return
	 */
	public Query addNewKeywords(List<String> keyWordsToAdd) {
		List<String> keyWords = new LinkedList<String>(this.keywords);
		keyWords.addAll(keyWordsToAdd);
		
		return new Query(keyWords, this.precision);
	}
	
	@Override
	public String toString() {
		StringBuilder buff = new StringBuilder();
		buff.append("Query keywords:[");
		for (String word : this.keywords) {
			buff.append(" ").append(word);
		}
		buff.append(" ], precision=").append(this.precision);
		return buff.toString();
	}

}
